//
//  ShareViewController.m
//  gpos_app
//
//  Created by 崔航飞 on 2018/8/26.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "ShareViewController.h"
#import "Masonry.h"
#import "CIImage+Extension.h"
@interface ShareViewController ()<UIGestureRecognizerDelegate>
@property (nonatomic,strong) UIView *backgroundViews;
@property (nonatomic,strong) UIImageView *backImageView;
@property (nonatomic,strong) UIView *whiteView;
//显示二维码的imageView
@property (nonatomic,strong) UIImageView *EWMView;
@property (nonatomic, assign) BOOL first_push;
@property(nonatomic,strong)NSMutableArray *att;
@end

@implementation ShareViewController
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden=NO;
    //去掉返回的文字
    self.navigationController.navigationBar.topItem.title = @"";
    self.navigationItem.title=@"分享";
    
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
        
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    [self initUI];
}
-(void)initUI{
    self.backgroundViews=[[UIView alloc] init];
    self.backgroundViews.backgroundColor=[UIColor whiteColor];
    self.backgroundViews.userInteractionEnabled=YES;
    [self.view addSubview:self.backgroundViews];
    [self.backgroundViews mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).offset(kNavbarHeight);
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.height.equalTo(@(KmainScreenHeiht - kNavbarHeight - kBottomSafeHeight));
    }];
    
    self.backImageView=[[UIImageView alloc] init];
    self.backImageView.image=[UIImage imageNamed:@"bj_fenxiang"];
    self.backImageView.userInteractionEnabled = YES;;
    
    [self.backgroundViews addSubview:self.backImageView];
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.backgroundViews.mas_top);
        make.left.equalTo(self.backgroundViews.mas_left);
        make.right.equalTo(self.backgroundViews.mas_right);
        make.bottom.equalTo(self.backgroundViews.mas_bottom);


    }];

    self.whiteView=[[UIView alloc] init];
    self.whiteView.backgroundColor=[UIColor whiteColor];
    self.whiteView.layer.cornerRadius=4;
    self.whiteView.userInteractionEnabled=YES;
    [self.backImageView addSubview:self.whiteView];
    CGFloat WH =(self.view.frame.size.width-281)/2;
    [self.whiteView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.backImageView.mas_top).offset(84);
        make.left.equalTo(self.backImageView.mas_left).offset(WH);
        make.right.equalTo(self.backImageView.mas_right).offset(-WH);
        make.height.equalTo(@(331));

    }];
    /**
     *  2.生成CIFilter(滤镜)对象
     */
    CIFilter *filter = [CIFilter filterWithName:@"CIQRCodeGenerator"];

    /**
     *  3.恢复滤镜默认设置
     */
    [filter setDefaults];

    /**
     *  4.设置数据(通过滤镜对象的KVC)
     */
    //存放的信息
    NSString *info = @"https://active.clewm.net/FOXAlM?qrurl=http%3A%2F%2Fqr10.cn%2FFOXAlM&gtype=1&key=781311520d7e2bf2835962b10bb22b97c35e5af289";
    //把信息转化为NSData
    NSData *infoData = [info dataUsingEncoding:NSUTF8StringEncoding];
    //滤镜对象kvc存值
    [filter setValue:infoData forKeyPath:@"inputMessage"];

    /**
     *  5.生成二维码
     */
    CIImage *outImage = [filter outputImage];
    self.EWMView=[[UIImageView alloc] init];
    self.EWMView.image = [outImage createNonInterpolatedWithSize:150];
    self.EWMView.userInteractionEnabled=YES;
   
    UILongPressGestureRecognizer * longPressGr = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressErweima:)];
    longPressGr.delegate=self;
    longPressGr.minimumPressDuration = 0.5;
    longPressGr.numberOfTouchesRequired = 1;
    [self.EWMView addGestureRecognizer:longPressGr];
    self.EWMView.backgroundColor=[UIColor whiteColor];
    [self.whiteView addSubview:self.EWMView];
    [self.EWMView mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.whiteView.mas_top).offset(68);
        make.left.equalTo(self.whiteView.mas_left).offset(59);
        make.right.equalTo(self.whiteView.mas_right).offset(-59);
        make.height.equalTo(@(160));

    }];
    
    UILabel *lab=[[UILabel alloc] init];
    lab.text=@"长按可识别二维码";
    lab.textAlignment=NSTextAlignmentCenter;
    lab.textColor=[UIColor colorWithRed:102/255 green:102/255 blue:102/255 alpha:1];
    lab.font=[UIFont systemFontOfSize:14];
    [self.whiteView addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {

        make.top.equalTo(self.EWMView.mas_bottom).offset(5);
        make.left.equalTo(self.whiteView.mas_left);
        make.right.equalTo(self.whiteView.mas_right);
        make.bottom.equalTo(self.whiteView.mas_bottom).offset(-5);
    }];
    
}

//长按手势分享图片
-(void)longPressErweima:(UILongPressGestureRecognizer *)gesture
{
    if(gesture.state == UIGestureRecognizerStateBegan)
    {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://active.clewm.net/FOXAlM?qrurl=http%3A%2F%2Fqr10.cn%2FFOXAlM&gtype=1&key=781311520d7e2bf2835962b10bb22b97c35e5af289"]];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
